source('00_util_scripts/mod_bplot.R')
library(tidyplots)

pctest <- read_tsv('virtual_screen_v3/data/qpcr.pc.test.txt')

pc.tidy <- pctest |>
  pivot_longer(-1) |>
  mutate(group = str_remove(name, '\\..+') |>
           case_match('300' ~ '300uM',
                      '600' ~ '600uM',
                      .default = 'DMSO')) 

pc.tidy |>
  tidyplot(gene, value, color = group) |>
  add_mean_bar() |>
  add_data_points_beeswarm(color = 'black') +
  labs(y = 'Fold change',
       title = 'A431 after carvacrol stimulation')

t0428 <- read_tsv('virtual_screen_v3/data/qp0428.txt')

tidy0428 <- t0428 |>
  pivot_longer(-1) |>
  mutate(group = str_remove(name, '\\..+')) 

tidy0428 |>
  tidyplot(gene, value, color = group) |>
  add_data_points_beeswarm() |>
  add_mean_bar() +
  labs(y = 'Fold change',
       title = 'A431 after stimulation')

t0501 <- read_tsv('virtual_screen_v3/data/qp0501.txt')

tidy0501 <- t0501 |>
  pivot_longer(-1) |>
  mutate(group = str_remove(name, '\\..+')) 

ljj <- tidy0501 |>
  bind_rows(tidy0428) |>
  mutate(group = str_replace(group, '可', 'IDHL') |>
           str_replace('43', 'CAS43') |> str_replace('77', 'CAS77') |>
           str_replace('00', '00uM') |> str_replace('50', '50uM') |>
           str_replace('25', '25uM') |> str_replace('rol', 'rol 300uM'),
         group = fct_relevel(group, 'DMSO', 'Carvacrol 300uM'))

plot_ljj <- function(goi) {
  ljj |>
  filter(gene == goi) |>
  tidyplot(group, value, color = group, width = 100) |>
  adjust_x_axis(rotate_labels = T) |>
  add_mean_bar() |>
  add_data_points_beeswarm(color = 'black') +
  labs(y = 'Fold change',
       title = str_glue('{goi} after stimulation'))
}

plot_ljj('IL8')
plot_ljj('IL6')
